<script>
		function openForm(id){
		if(id=='1'){
			
			jQuery("#form1").show();
			jQuery("#form3").hide();
			jQuery("#tab3").removeClass();
            jQuery("#tab1").addClass("current");
			jQuery("#scancode").focus();

		}else if(id=='3'){
			jQuery("#form1").hide();
			jQuery("#form3").show();
			jQuery("#tab1").removeClass();
            jQuery("#tab3").addClass("current");
			jQuery("#scancode2").focus();
		}
	}

	function checkScanCode(){
		if (jQuery('#send').is(":disabled")){
		var scancode=jQuery("#scancode").val();
		jQuery.ajax({
	  		type: "POST",
	  		url: "api/",
	  		dataType : 'json',   
			data: {action: "check_scan_code",scan_code:scancode}, 
			beforeSend: function ( xhr ) {
				jQuery("#messageLoader").show();
			}
			}).done(function(data) {
					jQuery("#messageLoader").hide();
					if(data['stat']==0){
						jQuery("#success").hide();
						jQuery("#failed").show();
						var error=data['error'];
						jQuery("#reason").text(error);
						
					}else{
						jQuery("#success").show();
						jQuery("#failed").hide();
						jQuery("#type_check").val(data['type']);
						jQuery("#year_check").val(data['year']);
						jQuery("#season_check").val(data['season']);
						jQuery("#flow_check").val(data['flow']);
						jQuery("#material_check").val(data['material']);
						jQuery("#color_check").val(data['color']);
						jQuery("#size_check").val(data['size']);
						jQuery("#scan_code_check").val(data['scan_code']);
						jQuery('#send').removeAttr('disabled');
						jQuery('#scancode').attr('readonly', 'readonly');
						jQuery('#check').text('重新扫描');
					}
					
			});
			
			
			}else{
						jQuery('#send').attr('disabled', 'disabled');
				
		jQuery('#scancode').removeAttr('readonly');
		jQuery('#scancode').focus();
		jQuery('#check').text('检验');
			}
		}

		jQuery(document).ready(function() {
					jQuery("#scancode").focus(function(){
 					jQuery(this).val("");
					});
						jQuery("#scancode2").focus(function(){
					 						jQuery(this).val("");
					});
					jQuery("#scancode").focus();
					//jQuery("#scancode2").focus();
					
					jQuery("#scancode").keydown(
					function (e, inputElement) {
						return false;
					});
					jQuery("#scancode2").keydown(
					function (e, inputElement) {
						return false;
					});
		});
</script>

	<div class="block">
	<div class="invertedshiftdown">
		<ul>
			<li><a href="?page=manage_users">用户管理</a></li>
			<li><a href="?page=manage_organizations">机构管理</a></li>
			<li class="current"><a href="?page=manage_items">产品管理</a></li>
			<li><a href="?page=manage_stack">下达入库指令</a></li>
            <li><a href="?page=manage_transaction">撤销错误记录（慎用）</a></li>
 		</ul>
		<form id="myform">
			<input type="text" class="textinput" /> <input class="submit" type="submit" value="搜索" />
		</form>
	</div>
	<br style="clear: both;" />
	<div id= 'content'>
	<br>
	<h2>管理菲雪》产品管理</h2>
	
	
	
	<?php
	//print_r($_GET);
	if(isset($_GET['stat'])){
		if($_GET['stat']=='inserted'){
			
		
	
	?>
	<div class="isa_success">
		<h4>操作成功：</h4>添加新产品
	</div>
	<?php }elseif($_GET['stat']=='error'&&$_GET['error']=='duplicated'){ ?>
	<div class="isa_error">
		<h4>操作失败：</h4>无法添加新产品（此条形码已经存在于数据库中）
	</div>
	<?php }elseif($_GET['stat']=='error'&&$_GET['error']=='format'){ ?>
	<div class="isa_error">
		<h4>操作失败：</h4>您刚刚扫描了12位和14位的条形码去旧条形码栏里，请重新扫描。
	</div>
	<?php }elseif($_GET['stat']=='error'&&$_GET['error']=='notExist'){ ?>
	<div class="isa_error">
		<h4>操作失败：</h4>无法更改新产品（此条形码不存在于数据库
	</div>
	<?php }elseif($_GET['stat']=='altered'){ ?>
	<div class="isa_success">
		<h4>操作成功：</h4>更改产品
	</div>
		<?php }elseif($_GET['stat']=='error'&&$_GET['error']=='badData'){ ?>
	<div class="isa_error">
		<h4>操作失败：</h4>无法添加/更改产品（提交了无效数据）
	</div>
<?php }
		}

		global $itemType;
		global $itemTopSize;
		global $itemSize;
		global $itemColor;
		global $itemMaterial;
		global $itemSeason;
		global $itemYear;
		global $itemType;
		global $itemDesigner;
		global $organizationType;
		echo $table;
	?>
	
<br>
<br>

	<h4>添加产品：</h4>

<div style="clear:both;">
		<ol id="toc">
		    <li id='tab1'class="current"><a href="#form1"><span onclick="openForm('1')">新扫描条码</span></a></li>
		    <li id='tab3'><a href="#form3"><span onclick="openForm('3')">旧扫描条码</span></a></li>
		</ol>
		<table style="width:100%">
			<tbody>
				<tr>
					<td style="width:50%">
    <div id="form1" class="form" style="display: block">
    	
    	<h4 style="color:red">新条形码只接受14或12位</h4>
        <form action="api/" method="post">
        	<input type="hidden" id='action' name="action" value="add_item" />
        	<input type="hidden" id='option' name="option" value="scan_code" />

        	<input type="hidden" id='uid' name="uid" value=<?php echo $currentUser -> id; ?> />
          
            <div class="element">
             <label class="form">扫描条码</label>
             	<input id="scancode" type="text" id="scan_code" name="scan_code" class="text" maxlength="14" size="18" >
            	<div id="check" class="button blue" onclick="checkScanCode()">检验</div>
            </div>
      		
   <div class="element" style="clear:both;">
        <label class="form">设计师代码</label>
        
        <div class='checkbox'>
        	<?php
        	foreach($itemDesigner as $key => $value)
        	{
        		
				if($key=='O'){
        	?>
                <input type="radio" name="designer" value="<?php echo $key; ?>" checked="checked">设计师：<?php echo $value; ?><br>
            <?php }else{ ?>
			    <input type="radio" name="designer" value="<?php echo $key; ?>" >设计师：<?php echo $value; ?><br>
			<?php }
					}
        	?>
     </div>

    </div>
    
    <div class="element" style="clear:both;">
        <label class="form">销售与否</label>
        
        <div class='checkbox'>

                <input type="radio" name="active" value="1" checked="checked">是<br>
     
			    <input type="radio" name="active" value="0" >否<br>
	
     </div>

    </div>
     <div class="element">
             <label class="form">产品名称</label>
             <input type="text"  name="name" class="text" maxlength="30" size="30" value="未知">
      </div>
     <div class="element">
             <label class="form">官方定价</label>
             <input type="text"  name="price" class="text" maxlength="6" size="6" value="100.0">
      </div>
      <div class="element">
             <label class="form">打折(%)</label>
             <input type="text"  name="ratio" class="text" maxlength="6" size="6" value= "100"><div>%</div>
      </div>

    <div class="element">
<input id="send" type="submit" value="递交" disabled="disabled" />
        <div class="loading"></div>
    </div>
    </form>
    </div>
    <div id="form3" class="form" style="display: none;">
    	
    	<h4 style="color:red">可任意输入任何位数扫描条码</h4>
        <form action="api/" method="post">
        	<input type="hidden" id='action' name="action" value="add_item" />
        	<input type="hidden" id='option' name="option" value="random" />

        	<input type="hidden" id='uid' name="uid" value=<?php echo $currentUser -> id; ?> />
          
            <div class="element">
             <label class="form">扫描条码</label>
             	<input id="scancode2" type="text" id="scan_code" name="scan_code" class="text" maxlength="14" size="18" >
            </div>
      		
   <div class="element" style="clear:both;">
        <label class="form">设计师代码</label>
        
        <div class='checkbox'>
        	<?php
        	foreach($itemDesigner as $key => $value)
        	{
        		
				if($key=='O'){
        	?>
                <input type="radio" name="designer" value="<?php echo $key; ?>" checked="checked">设计师：<?php echo $value; ?><br>
            <?php }else{ ?>
			    <input type="radio" name="designer" value="<?php echo $key; ?>" >设计师：<?php echo $value; ?><br>
			<?php }
					}
        	?>
     </div>

    </div>
    
    <div class="element" style="clear:both;">
        <label class="form">销售与否</label>
        
        <div class='checkbox'>

                <input type="radio" name="active" value="1" checked="checked">是<br>
     
			    <input type="radio" name="active" value="0" >否<br>
	
     </div>

    </div>
     <div class="element">
             <label class="form">产品名称</label>
             <input type="text"  name="name" class="text" maxlength="30" size="30" value="未知">
      </div>
     <div class="element">
             <label class="form">官方定价</label>
             <input type="text"  name="price" class="text" maxlength="6" size="6" value="100.0">
      </div>
      <div class="element">
             <label class="form">打折(%)</label>
             <input type="text"  name="ratio" class="text" maxlength="6" size="6" value= "100"><div>%</div>
      </div>

    <div class="element">
<input type="submit" value="递交" />
        <div class="loading"></div>
    </div>
    </form>
    </div>
       <?php $page = 'manage_item';
		//include ('view/itemUpload.php');
    ?>
		    	</td>

				<td style="width:50%;padding-top:0px;margin-top:0px">
					<div id="failed" style="display:none">
					  <div class="element">
             <h2>检测结果：不符合</h2>
				   				 </div>
			<div class="element">
             <h2>错误原因:</h2>
             <h2 id="reason" style="color: red"></h2>
			 </div>			
			 <div class="element">
             <h2>请参考下面文档</h2>
			 <a href="?page=intro_scan_code">旧编码系统详解</a>
			 <a href="?page=intro_scan_code2013">2013编码系统详解</a>
			 </div>
			 </div>
			 <div id="success" style="display:none">
					  <div class="element">
             <h2>检测结果：符合规则</h2>
                          <h2 id="scan_code" style="color: white"></h2>

				   				 </div>
				 
			<div class="element">
				
             <label class="form">类型:</label>
             <input id="type_check"  type="text" class="text" style="color: white" readonly="readonly">
			 </div>	
			<div class="element">
				
             <label class="form">年份:</label>
             <input id="year_check"  type="text" class="text" style="color: white" readonly="readonly">
			 </div>	
			 		
			 <div class="element">
				
             <label class="form">季节:</label>
             <input id="season_check"  type="text" class="text" style="color: white" readonly="readonly">
			 </div>	
		 	<div class="element">
				
             <label class="form">流水号:</label>
             <input id="flow_check"  type="text" class="text" style="color: white" readonly="readonly">
			 </div>				 		
			 <div class="element">
				
             <label class="form">面料:</label>
             <input id="material_check"  type="text" class="text" style="color: white" readonly="readonly">
			 </div>			
			 <div class="element">
				
             <label class="form">颜色:</label>
             <input id="color_check"  type="text" class="text" style="color: white" readonly="readonly">
			 </div>		
			 <div class="element">
				
             <label class="form">尺码:</label>
             <input id="size_check"  type="text" class="text" style="color: white" readonly="readonly">
			 </div>				 
			 </div>
		    		<center id='messageLoader' style="background-color: #ECECEC;padding-top: 0px; display:none"><img src="images/ajax-loader.gif"></center>
		    	</td>
		 	</tr>
   		</tbody>
    </table>
    </div>
<div style="clear:both;">

    
    </div>
    <div style="clear:both;">

    
    </div>
    </div>
<div class="clear"></div>
<br>
	</div>